﻿using System;

namespace Golang.Ioc
{




    internal class Program
    {

        private static void Main(string[] args)
        {
            CheckDemo();
            StringDemo();
            PrintGCInfo();
            StringTest();
            PrintGCInfo();

        }

        private static void CheckDemo()
        {
            Console.WriteLine($"Check(1,2):{NativeLib.Check(1, 2)}");
            Console.WriteLine($"Check(2,2):{NativeLib.Check(2, 2)}");
            Console.WriteLine($"Check(3,2):{NativeLib.Check(3, 2)}");
        }

        private static void StringDemo()
        {
            var r = NativeLib.GetSlogan("你好,我是C#!");
            Console.WriteLine(r);
        }


        private static void PrintGCInfo()
        {
            //打印垃圾回收信息

            // Determine the maximum number of generations the system
            // garbage collector currently supports.
            Console.WriteLine("系统支持最高世代 {0}", GC.MaxGeneration);

            // Determine the best available approximation of the number
            // of bytes currently allocated in managed memory.
            Console.WriteLine("当前分配内存: {0}", GC.GetTotalMemory(false));

        }

        private static void StringTest()
        {
            var total = 0;
            Console.WriteLine($"输入每轮调用的次数");
            var line = Console.ReadLine();
            int num;
            int count = 10000;

            if (int.TryParse(line, out num))
            {
                count = num;
            }
            Console.WriteLine($"当前每轮调用 {count} 次, 开始第一轮测试");


            while (!line.Equals("q", StringComparison.CurrentCultureIgnoreCase))
            {
                for (int i = 0; i < count; i++)
                {
                    total++;
                    NativeLib.GetSlogan("你好,我是C#!");
                }
                PrintGCInfo();
                Console.WriteLine($"调用 {total} 次,输入q 退出,其他继续测试");
                line = Console.ReadLine();
            }
        }
    }
}